import {Component} from '@angular/core';
import {App, IonicPage, NavController, NavParams} from 'ionic-angular';
import {CleanningDatailPage} from "../cleanning-datail/cleanning-datail";
import {ROUTER} from "../../service/router.service";
import {CleaningModel} from "../../model/cleaning.modal";
import moment from "moment"
import {GOODS} from "../../api/goods-api";
import {PageParam} from "../../api/api.service";
import {CheckStandModel} from "../../model/checkstand.model";
import {LocalStorage} from "../../utils/localstorage.utils";

/**
 * Generated class for the MyCleaningPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-my-cleaning',
  templateUrl: 'my-cleaning.html',
})
export class MyCleaningPage {
  pageParam:PageParam;
  hasMore:boolean = true;
  orderList = [];

  constructor(public ls:LocalStorage,public GOODS:GOODS, public navCtrl:NavController, public app:App, public navParams:NavParams, private ROUTER:ROUTER) {

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MyCleaningPage');
    this.pageParam = new PageParam();
    this.doRefresh();
    // this.GOODS.getOrderList((v)=>{
    //   console.log(v)
    // },this.pageParam)

  }

  gotocleanDetail(v) {
    this.ROUTER.go(ROUTER.MACLEANDATAIL,v.id);
  }

  ionViewDidEnter() {
    document.title = '我的保洁';
  }

  doRefresh(refresher?) {
    this.pageParam = new PageParam()
    this.GOODS.getCleanOrderList(v => {
      this.orderList = v.content
      this.hasMore = !v.last;
      if (refresher) {
        refresher.complete();
      }
    }, this.pageParam);
  }

  get canLoadMore():boolean {
    return this.hasMore;
  }

  doInfinite(infiniteScroll) {
    ++this.pageParam.page;
    this.GOODS.getCleanOrderList(v => {
      this.hasMore = !v.last;
      this.orderList = this.orderList.concat(v.content);
      infiniteScroll.complete();
    }, this.pageParam);
  }

  gotoCheckstand(v) {
    let checkstand = new CheckStandModel(v.orderNo, v.title, v.totalMoney, v.id, ROUTER.MYCLEANING)
    this.ls.setObject('checkstand', checkstand);
    this.ROUTER.go(ROUTER.CHECK);
  }

}
